﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Ebada.Components;
using Ebada.Client.Platform;
using Ebada.Platform.Model;
using DevExpress.XtraEditors;
namespace Ebada.Modules.Document
{
    public partial class frmImageSel : XtraForm
    {
        private string parentid = "";

        public string ParentID
        {
            get { return parentid; }
            set { parentid = value; }
        }
        public string DocTitle
        {
            get { return textEdit1.Text; }
            set { textEdit1.Text = value; }
        }
        public string DocCont
        {
            get { return memoEdit1.Text; }
            set { memoEdit1.Text = value; }
        }
        public frmImageSel()
        {
            InitializeComponent();
        }

        private void buttonEdit1_Properties_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                buttonEdit1.Text = openFileDialog1.FileName;
            }
        }

       /* private void buttonEdit2_Properties_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                buttonEdit2.Text = openFileDialog1.FileName;
            }
        }*/

        private void buttonEdit3_Properties_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                buttonEdit3.Text = openFileDialog1.FileName;
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (textEdit1.Text == "")
            {
                MessageBox.Show("图片标题不能为空。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                textEdit1.Focus();
                return;
            }
            if (buttonEdit1.Text == "")
            {
                MessageBox.Show("图片文件不能为空。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
          
            if (buttonEdit3.Text == "")
            {
                MessageBox.Show("电子文档内容不能为空。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            FuncLib f = new FuncLib();
            DocumentImage img = new DocumentImage();
            img.DocumentImageID = Guid.NewGuid().ToString();
            img.DocumentID = parentid;
            img.DocTitle = textEdit1.Text;
            img.TextContents = memoEdit1.Text;
            img.DocImage = f.GetImageBate(buttonEdit1.Text);
            //img.DocImage2 = f.GetImageBate(buttonEdit2.Text);
            img.DocFile = f.GetImageBate(buttonEdit3.Text);
            img.CreateUserID = MainHelper.UserBaseX.User_ID;
            img.CreateUserName=MainHelper.UserBaseX.Empolyee_Name;
            img.CreatedDate = DateTime.Now;
            MainHelper.GetSqlMap<DocumentImage>().Create<DocumentImage>(img);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
